//
//  NewPlanDuanxinViewController.m
//  wangzhe
//
//  Created by 李 佳伟 on 2018/3/27.
//  Copyright © 2018年 李 佳伟. All rights reserved.
//

#import "NewPlanDuanxinViewController.h"
#import "JTCSM.h"
#import "MyInfoView.h"
#import "RegisterVIew.h"
static CGFloat myinfoHeight = 50;
@interface NewPlanDuanxinViewController ()<UITextFieldDelegate>
{
    UIView *alertbackview;
}
@end

@implementation NewPlanDuanxinViewController

- (void)gotBack{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.hidden = NO;
    [df isRemoveTarbar:YES];
    self.view.backgroundColor = RGBACOLOR(241, 241, 241, 1);
    leftBarButtonItems_rightBarButtonItems *leftbtn = KCUSTOMNAVIGSTION_ALLOC;
    self.navigationItem.leftBarButtonItem = [leftbtn setBarButtonItemsImageName:@"fanhui.png" frame:KLeftBarButtonItemFrame_image target:self SEL:@selector(gotBack)];
    // Do any additional setup after loading the view.
    [self.view addSubview:[self layouHeaderViewWithFirstName:@"民生银行（3443）" firstimage:@"" secondname:@"民生银行（3443）" secondimage:@""]];
    [self layousubviews];
}
- (UIView *)layouHeaderViewWithFirstName:(NSString *)firstname firstimage:(NSString *)firstimage secondname:(NSString *)secondname secondimage:(NSString *)secondimage{
    UIView *backview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KCONTROLLERWith, 120)];
    backview.backgroundColor = RGBACOLOR(241, 241, 241, 1);
    backview.userInteractionEnabled = YES;
    
    UIView * showView = [[UIView alloc]initWithFrame:CGRectMake(10, 10, backview.LC_width-20, backview.LC_height-20)];
    showView.backgroundColor = [UIColor whiteColor];
    [df layerWithView:showView radius:4 width:0 color:nil];
    [backview addSubview:showView];
    
    CGFloat space = 20;
    CGFloat banklogoImagesize = 40;
    CGFloat zhixiangImageWidth = 80;
    CGFloat zhixiangImageHeight = zhixiangImageWidth*0.161347;
    CGFloat changespace = (showView.LC_width-2*space-2*banklogoImagesize-zhixiangImageWidth)/4;
    NSString *str = @"测试数据";
    CGFloat font = 14;
    CGRect rect  = [df labelHeightWithContent:str height:30 font:font];
    CGFloat changetop = 15;
    CGFloat banktop = (showView.LC_height-banklogoImagesize-rect.size.height-changetop)/2;
    
    UIImageView *firstimagev = [[UIImageView alloc]initWithFrame:CGRectMake(space+changespace, banktop, banklogoImagesize, banklogoImagesize)];
    firstimagev.image = [UIImage imageNamed:firstimage];
    [showView addSubview:firstimagev];
    
    UILabel *firstlabel = [UILabel initWithFrame:CGRectMake(0, KVIEW_Y(firstimagev)+changetop, KCONTROLLERWith/2, rect.size.height) text:firstname font:font textAlignment:NSTextAlignmentCenter texcolor:[df colorWithHexString:@"333333" alpha:1] backgroundColor:nil];
    [showView addSubview:firstlabel];
    
    
    UIImageView *zhixiangimagev = [[UIImageView alloc]initWithFrame:CGRectMake(KVIEW_X(firstimagev)+changespace, showView.LC_height/2-zhixiangImageHeight, zhixiangImageWidth, zhixiangImageHeight)];
    zhixiangimagev.image = [UIImage imageNamed:@"bank箭头.png"];
    [showView addSubview:zhixiangimagev];
    UILabel *alertLabel = [UILabel initWithFrame:CGRectMake(zhixiangimagev.LC_x, showView.LC_height/2, zhixiangImageWidth, zhixiangImageHeight) text:@"向该银行还款" font:11 textAlignment:NSTextAlignmentRight texcolor:[df colorWithHexString:@"999999" alpha:1] backgroundColor:nil];
    [showView addSubview:alertLabel];
    
    
    UIImageView *secondimagev = [[UIImageView alloc]initWithFrame:CGRectMake(KVIEW_X(alertLabel)+changespace, banktop, banklogoImagesize, banklogoImagesize)];
    secondimagev.image = [UIImage imageNamed:secondimage];
    [showView addSubview:secondimagev];
    
    UILabel *secondlabel = [UILabel initWithFrame:CGRectMake(KCONTROLLERWith/2, KVIEW_Y(secondimagev)+changetop, KCONTROLLERWith/2, rect.size.height) text:secondname font:font textAlignment:NSTextAlignmentCenter texcolor:[df colorWithHexString:@"333333" alpha:1] backgroundColor:nil];
    [showView addSubview:secondlabel];
    return backview;
}

- (void)layousubviews{
    NSArray *array = @[@"总还款金额",@"还款期限",@"开始日期",@"结束日期"];
    NSArray *contentarray = @[@"¥10000.00",@"5天",@"2018-04-12",@"2018-04-17"];
    for (int i = 0; i < array.count; i++) {
        MyInfoView *view1 = [[MyInfoView alloc]initWithFrame:CGRectMake(0, 120+myinfoHeight*i, KCONTROLLERWith, myinfoHeight) imagename:nil title:array[i]placeholder:nil isShowLabel:labelType radioBtnIndex:0 GroupId:@""];
        view1.footerLabel.text = contentarray[i];
        view1.footerLabel.textColor = [df colorWithHexString:@"333333" alpha:1];
        view1.tag = 100+i;
        view1.userInteractionEnabled = YES;
        [self.view addSubview:view1];
    }
    [df newlineViewWithHeightofTop:120+myinfoHeight*4+10 superView:self.view spacing:0 color:RGBACOLOR(241, 241, 241, 1) lineHeight:10];
   NSArray *placeholderArray=@[@"输入验证码"];
    RegisterVIew *registerV;
    for (int i = 0; i < placeholderArray.count; i++) {
       registerV = [[RegisterVIew alloc]initWithFrame:CGRectMake(0,120+myinfoHeight*4+10, self.view.frame.size.width, myinfoHeight) labeTtext:nil placeholder:placeholderArray[i]];
        registerV.userInteractionEnabled =YES;
        registerV.backgroundColor = [UIColor whiteColor];
        registerV.textField.textAlignment= NSTextAlignmentLeft;
        registerV.textField.tag = 100+i;
        registerV.tag = 1000+i;
        [registerV.textField setValue:RGBACOLOR(120, 130, 140,1) forKeyPath:@"_placeholderLabel.textColor"];
        registerV.label.textAlignment = NSTextAlignmentLeft;
        [self.view addSubview:registerV];
        [self addImageWith:registerV];
        registerV.textField.delegate = self;
        [registerV.textField addTarget:self  action:@selector(valueChanged:)  forControlEvents:UIControlEventAllEditingEvents];
        if (i ==placeholderArray.count-1) {
            CGFloat btnHeight = 30;
          UIButton  *getKeyBtn = [UIButton initWithFrame:CGRectMake(KCONTROLLERWith-KBtnWidth-13, registerV.frame.origin.y+(myinfoHeight-btnHeight)/2, KBtnWidth-5, btnHeight) backgrandColor:nil titleColor:RGBACOLOR(89, 89, 89, 1 ) title:@"获取验证码" titleFont:12];
            [getKeyBtn addTarget:self action:@selector(getToKey) forControlEvents:UIControlEventTouchUpInside];
            [self.view addSubview:getKeyBtn];
            [df layerWithView:getKeyBtn radius:15 width:1 color:KZhuTiRGB];
            registerV.textField.frame = CGRectMake(registerV.textField.frame.origin.x, registerV.textField.frame.origin.y, registerV.textField.frame.size.width-KBtnWidth-10, registerV.textField.frame.size.height);
        }
    }
    
    
    UIButton *tijiaobutton = [UIButton buttonWithType:UIButtonTypeCustom];
    tijiaobutton.frame = CGRectMake(25, KVIEW_Y(registerV)+30, KCONTROLLERWith-40, 50);
    [tijiaobutton addTarget:self action:@selector(tijiao) forControlEvents:UIControlEventTouchUpInside];
    [df layerWithView:tijiaobutton radius:25 width:0 color:nil];
    tijiaobutton.backgroundColor = KZhuTiRGB;
    [tijiaobutton setTitleColor:RGBACOLOR(51, 51, 51, 1) forState:UIControlStateNormal];
    [tijiaobutton setTitle:@"确认提交" forState:UIControlStateNormal];
    [self.view addSubview:tijiaobutton];

    
}
#pragma mark --添加灰线条
-(void)addImageWith:(UIView *)fatherview{
    
    UILabel *lable =[[UILabel alloc] initWithFrame:CGRectMake(20,  0, 77, myinfoHeight-1.5)];
    [lable setText:@"验证码"];
    lable.textAlignment=YES;
    lable.textAlignment = NSTextAlignmentLeft;
    lable.backgroundColor =[UIColor whiteColor];
    lable.font =[UIFont fontWithName:@"Arial" size:15.0];
    [fatherview addSubview:lable];
    
    
}
- (void)addLineWith:(UIView *)fatherview{
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(20, fatherview.frame.size.height-1.5, KCONTROLLERWith-40, 1.5)];
    view.backgroundColor = RGBACOLOR(226, 227, 228,1);
    [fatherview addSubview:view];
    
}

- (void)getToKey{
    
}
- (void)valueChanged:(UITextField *)textfield{
    
}
- (void)tijiao{
    [self alertView];
}

- (void)alertView{
    alertbackview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KSCREENWidth, KSCREENHeight)];
    alertbackview.backgroundColor = RGBACOLOR(0, 0, 0, 0.3);
    alertbackview.userInteractionEnabled = YES;
    [[JTCSMSingle shareSingle].theWindow addSubview:alertbackview];
    UIView *showview = [[UIView alloc]initWithFrame:CGRectMake(65, (KSCREENHeight-70)/2, alertbackview.LC_width-130, 70)];
    showview.backgroundColor = [UIColor whiteColor];
    showview.userInteractionEnabled = YES;
    [alertbackview addSubview:showview];
    [df layerWithView:showview radius:10 width:0 color:nil];
    CGFloat imagesize = 30;
    NSString *str = @"短线验证通过";
    CGFloat font = 16;
    CGRect rect = [df labelHeightWithContent:str width:1000 font:font];
    CGFloat space = (showview.LC_width-imagesize-rect.size.width-14)/2;
    UIImageView *imageV = [[UIImageView alloc]initWithFrame:CGRectMake(space, (showview.LC_height-imagesize)/2, imagesize, imagesize)];
    imageV.image = [UIImage imageNamed:@"钱包充值_支付成功.png"];
    [showview addSubview:imageV];
    UILabel *titleLabel = [UILabel initWithFrame:CGRectMake(KVIEW_X(imageV)+14, (showview.LC_height-rect.size.height)/2, rect.size.width, rect.size.height) text:str font:font textAlignment:NSTextAlignmentCenter texcolor:[df colorWithHexString:@"333333" alpha:1] backgroundColor:nil];
    [showview addSubview:titleLabel];
    [df addTapGestureRecognizerWithTarget:self action:@selector(gotoback) andaddView:alertbackview];
}
- (void)gotoback{
    [alertbackview removeFromSuperview];
    UIViewController *viewCtl = self.navigationController.viewControllers[1];

    [self.navigationController popToViewController:viewCtl animated:NO];
    [[NSNotificationCenter defaultCenter]postNotificationName:@"gotoJiluVC" object:nil userInfo:nil];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
